<?php

class ErrorController extends Zend_Controller_Action {

	const NOTICE = 'notice';
    const WARNING = 'warning';   
    const CRITICAL = 'critical';

    public function init() {
    }
 
    public function indexAction() {
		$this->_forward('error');
    }

    public function errorAction() {

		$errorLevel = self::WARNING;
        $errorTitle = 'unknown_error';
		$errorMessage = 'fatal_error_occured_during_processing';
        $httpCode = 500;
   	
	$exception = $this->_getParam('error_handler',null);

	if (isset($exception)) {

    	//$logger = Zend_Registry::get('logger');

        switch ($exception->type) {
       	    	case Zend_Config_Exception:
	            $httpCode = 500; 
	            $errorTitle = 'La aplicaciÛn no esta configurada';         			
        	    break;
        		
            	case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
            	case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
		    $httpCode = 404;
	            $errorTitle = 'Page not found';
		    $errorMessage = 'The page you requested cannot be found. The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.';  
        	    break;
        
           	case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_OTHER: 
			switch (get_class($this->_exception->exception)) { 
	 	             	case 'Zend_View_Exception' : 
	        	        	$httpCode = 500; 
	               			$errorTitle = 'view_processing_error'; 
					
	              			break; 
	              		case 'Zend_Db_Exception' : 
	              		case 'Zend_Db_Table_Row_Exception':
	               			$httpCode = 503; 
	               			$errorTitle = 'database_processing_error'; 
	              			break; 
           	      		default:
	               			$httpCode = 500;
		       			$errorTitle = 'unknown_error';
		       		break;
	   	     }       
        	}

		
		//$this->view->exception = $exception['exception'];
		//$logger->log(self::$httpCode.' '.self::$errorTitle,Zend_Log::CRIT);

     	}

	$this->_response->setHttpResponseCode($httpCode);

	print_r($this->view->exception);

	$this->view->level = $errorLevel;
	$this->view->title = $errorTitle;
	$this->view->message = $exception['exception']->getMessage() . $errorMessage; 
  }

      
}
